package com.mfangsoft.zhuangjialong.integration.taskdefine.controller;





import java.text.ParseException;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


import com.mfangsoft.zhuangjialong.common.model.ResponseMessage;
import com.mfangsoft.zhuangjialong.common.utils.SysConstant;

import com.mfangsoft.zhuangjialong.integration.taskdefine.model.BaseTaskDefine;
import com.mfangsoft.zhuangjialong.integration.taskdefine.service.TaskDefineService;





@Controller
@RequestMapping("/server")
public class TaskDefineController {
	
	@Autowired
	private TaskDefineService taskDefineService;
	
	/**
	 * 定义任务新增
	 * @param 
	 * @return
	 */
	
	@RequestMapping(value="/addTaskDefine",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<String> addTaskDefine(@RequestBody BaseTaskDefine baseTaskDefine){
		ResponseMessage<String> message = new ResponseMessage<String>();
	
		//baseActivityInfo.setCreater((String) session.getAttribute("user"));
		/*System.out.println(UserContext.getCurrentUser());
		System.out.println(UserContext.getCurrentUser().getUserInfoEntity().getName());*/
		try {
			
			taskDefineService.addTaskDefine(baseTaskDefine);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;

	}
	/**
	 * 定义任务列表
	 * @param 
	 * @return
	 */
	
	@RequestMapping(value="/selectTaskDefine",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<List<BaseTaskDefine>> selectTaskDefine(@RequestBody BaseTaskDefine baseTaskDefine){
		ResponseMessage<List<BaseTaskDefine>> message = new ResponseMessage<List<BaseTaskDefine>>();
	
		//baseActivityInfo.setCreater((String) session.getAttribute("user"));
		/*System.out.println(UserContext.getCurrentUser());
		System.out.println(UserContext.getCurrentUser().getUserInfoEntity().getName());*/
		try {
			
			//message.setResult(tagService.selectTag(baseTag));
			taskDefineService.selectTaskDefine(baseTaskDefine);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;

	}
	/**
	 * 定义任务导购
	 * @param 
	 * @return
	 * @throws  
	 */
	@RequestMapping(value="/updateTaskDefineOne",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<BaseTaskDefine> updateTaskDefineOne(@RequestBody BaseTaskDefine baseTaskDefine) throws ParseException{
		
		ResponseMessage<BaseTaskDefine> message = new ResponseMessage<BaseTaskDefine>();
		/*BaseActivityInfo baseActivityInfo = new BaseActivityInfo();
		baseActivityInfo.setId(25);*/
		try {
			//tagService.updateGiftOne(baseTag);
			taskDefineService.updateTaskDefineOne(baseTaskDefine);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 删除定义任务
	 * @param 
	 * @return
	 * @throws  
	 */
	
	@RequestMapping(value="/deleteTaskDefineOne/{id}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public  ResponseMessage<BaseTaskDefine> deleteTaskDefineOne(@PathVariable int id) throws ParseException{
		
		ResponseMessage<BaseTaskDefine> message = new ResponseMessage<BaseTaskDefine>();
		try {
		//	tagService.deleteTagOne(id);
			taskDefineService.deleteTaskDefineOne(id);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
}
